﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace GetCar
{
    public class CarPool
    {
        private static int PoolSize = 2;

        private static readonly List<Mini> MiniPool = new List<Mini>();
        private static readonly List<Sedan> SedanPool = new List<Sedan>();
        private static readonly List<Coupe> CoupePool = new List<Coupe>();

        private static List<Mini> MiniInUse = new List<Mini>();
        private static List<Coupe> CoupeInUse = new List<Coupe>();
        private static List<Sedan> SedanInUse = new List<Sedan>();

        public Mini GetMini(String Colour, String Transmission, String Moto)
        {
            Mini MiniCar;

            if (MiniPool.Count != 0)
            {
                Console.WriteLine("Mini from stock");
                foreach (Mini MiniLocalCar in MiniPool)
                {
                    if (MiniLocalCar.GetColour() == Colour && MiniLocalCar.GetTransmission() == Transmission && MiniLocalCar.GetMoto() == Moto)
                    {
                        int MiniPosition = MiniPool.IndexOf(MiniLocalCar);
                        MiniCar = MiniPool[MiniPosition];
                        MiniInUse.Add(MiniCar);
                        MiniPool.RemoveAt(MiniPosition);

                        Console.WriteLine("We have the exact Mini car you are looking for");

                        return MiniCar;
                    }
                }
                
                Console.WriteLine("We don't have the Mini with the characteristic you want, so we'll give you another one");
                        
                MiniCar = MiniPool[0];
                MiniInUse.Add(MiniCar);
                MiniPool.RemoveAt(0);

                return MiniCar;
                 
            }
            else
            {
                Console.WriteLine("New Mini car");
                MiniCar = new Mini(Colour, Transmission, Moto);
                MiniInUse.Add(MiniCar);

                return MiniCar;
            }
        }

        public void PutMiniBack(Mini MiniCar)
        {
            MiniPool.Add(MiniCar);
            MiniInUse.Remove(MiniCar);
            Console.WriteLine("Mini put back");
        }

        public Sedan GetSedan(String Colour, String Transmission, String Moto)
        {
            Sedan SedanCar;

            //daca sunt masini de tipul Mini in stoc
            if (SedanPool.Count != 0)
            {
                Console.WriteLine("Sedan from stock");
                foreach (Sedan SedanLocalCar in SedanPool)
                {
                    if (SedanLocalCar.GetColour() == Colour && SedanLocalCar.GetTransmission() == Transmission && SedanLocalCar.GetMoto() == Moto)
                    {
                        int SedanPosition = SedanPool.IndexOf(SedanLocalCar);
                        SedanCar = SedanPool[SedanPosition];
                        SedanInUse.Add(SedanCar);
                        SedanPool.RemoveAt(SedanPosition);
                        Console.WriteLine("We have the exact Sedan car you are looking for");

                        return SedanCar;
                    }
                }
                
              Console.WriteLine("We don't have the Sedan with the characteristic you want, so we'll give you another one");

              SedanCar = SedanPool[0];
              SedanInUse.Add(SedanCar);
              SedanPool.RemoveAt(0);
                    
              return SedanCar;
                
            }
            else
            {
                Console.WriteLine("New Sedan car");
                SedanCar = new Sedan(Colour, Transmission, Moto);
                SedanInUse.Add(SedanCar);

                return SedanCar;
            }
        }

        public void PutSedanBack(Sedan SedanCar)
        {
            SedanPool.Add(SedanCar);
            SedanInUse.Remove(SedanCar);
            Console.WriteLine("Sedan put back");
        }

        public Coupe GetCoupe(String Colour, String Transmission, String Moto)
        {
            Coupe CoupeCar;
            Console.WriteLine("Coupe from stock");
            //daca sunt masini de tipul Mini in stoc
            if (CoupePool.Count != 0)
            {
                foreach (Coupe CoupeLocalCar in CoupePool)
                {
                    if (CoupeLocalCar.GetColour() == Colour && CoupeLocalCar.GetTransmission() == Transmission && CoupeLocalCar.GetMoto() == Moto)
                    {
                        int CoupePosition = CoupePool.IndexOf(CoupeLocalCar);
                        CoupeCar = CoupePool[CoupePosition];
                        CoupeInUse.Add(CoupeCar);
                        CoupePool.RemoveAt(CoupePosition);
                        Console.WriteLine("We have the exact Coupe car you are looking for");

                        return CoupeCar;
                    }
                }


               Console.WriteLine("We don't have the Sedan with the characteristic you want, so we'll give you another one");

               CoupeCar = CoupePool[0];
               CoupeInUse.Add(CoupeCar);
               SedanPool.RemoveAt(0);

               return CoupeCar;
                
            }
            else
            {
                Console.WriteLine("New Coupe car");
                CoupeCar = new Coupe(Colour, Transmission, Moto);
                CoupeInUse.Add(CoupeCar);

                return CoupeCar;
            }
        }

        public void PutCoupeBack(Coupe CoupeCar)
        {
            CoupePool.Add(CoupeCar);
            CoupeInUse.Remove(CoupeCar);
            Console.WriteLine("Coupe put back");
        }

    }
}
